package org.ihelpuoo.weboo.util;

public class ForwardTarget
{

	private String	moduleName;
	private String	actionName;
	private String	path;

	public ForwardTarget(String s)
	{
		if (s.charAt(0) == '/')
			path = s;
		else
		{
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < s.length(); i++)
			{
				char c = s.charAt(i);
				if (c == '.')
				{
					moduleName = sb.toString();
					sb = new StringBuffer();
				}
				else
				{
					sb.append(c);
				}
			}
			actionName = sb.toString();
		}
	}

	public String getActionName()
	{
		return actionName;
	}

	public String getModuleName()
	{
		if (null == moduleName)
			moduleName = path.substring(1,path.indexOf(1,'/'));
		return moduleName;
	}

	public String getPath()
	{
		return path;
	}

	public String getActionPath(String suffix)
	{
		return new StringBuffer("/").append(moduleName).append('/').append(actionName).append(
				suffix).toString();
	}

	@Override
	public String toString()
	{
		if (isForAction())
			return new StringBuffer(moduleName).append('.').append(actionName).toString();
		return path;
	}

	public boolean isForAction()
	{
		return null != actionName;
	}

}
